import hashlib
import json
import os
import random
import time
import pandas as pd


def sleep(n_secs):
    time.sleep(n_secs)


def get_project_path():
    """得到项目路径"""
    return os.path.dirname(__file__)


def getPath(fileName: str):
    return os.path.join(os.path.dirname(__file__), "data", fileName)


def read_excel(fileName: str, sheet: int = 0):
    filePath = getPath(fileName)
    excel_data = pd.read_excel(filePath, sheet)
    return excel_data.values.tolist()


def getPhone():
    firstThreeNumber = ["134", "135", "136", "137", "138", "139", "147", "150", "152", "157", "158",
                        "159", "172", "178", "182", "183", "184", "187", "188", "198", "130", "131", "132", "145",
                        "155",
                        "156", "166", "171", "175", "176", "185", "186", "166", "133", "149", "153", "173", "177",
                        "180", "181",
                        "189", "199"]
    phone = random.choice(firstThreeNumber) + str(random.randint(10000000, 99999999))
    return phone


def get_md5(data):
    md5 = hashlib.md5()
    md5.update(data.encode('utf-8'))
    return md5.hexdigest()


def getSign(n):
    phoneNum = getPhone()
    ts = time.time()
    second = int(round(ts * 1000))
    toSign = f"{phoneNum}testfan{second}"
    sign = get_md5(toSign)
    dataList = []
    for i in range(n):
        dataList.append([phoneNum, second, sign])
    return dataList


def response_decode(response):
    """解码返回的html内容"""
    print(response)
    print(response.resp_obj)  # requests.response
    response.resp_obj.encoding = "utf-8"

if __name__ == '__main__':
    print(getSign(10))
